import 'dart:convert';

//工具日志信息
class ToolLog {
  int id;
  int status;
  String name;
  DateTime operateDate;
  String operator;
  ToolLog({
    required this.id,
    required this.status,
    required this.name,
    required this.operateDate,
    required this.operator,
  });

  ToolLog copyWith({
    int? id,
    int? status,
    String? name,
    DateTime? operateDate,
    String? operator,
  }) {
    return ToolLog(
      id: id ?? this.id,
      status: status ?? this.status,
      name: name ?? this.name,
      operateDate: operateDate ?? this.operateDate,
      operator: operator ?? this.operator,
    );
  }

  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'status': status,
      'name': name,
      'operateDate': operateDate.millisecondsSinceEpoch,
      'operator': operator,
    };
  }

  factory ToolLog.fromMap(Map<String, dynamic> map) {
    return ToolLog(
      id: map['id'] ?? 0,
      status: map['state'] ?? '',
      name: map['name'] ?? '',
      operateDate: DateTime.fromMillisecondsSinceEpoch(map['date']),
      operator: map['user'] ?? '',
    );
  }

  String toJson() => json.encode(toMap());

  factory ToolLog.fromJson(String source) =>
      ToolLog.fromMap(json.decode(source));

  @override
  String toString() {
    return 'ToolLog(id: $id, status: $status, name: $name, operateDate: $operateDate, operator: $operator)';
  }

  static List<ToolLog> toolLogList = [
    ToolLog(
        id: 12,
        status: 1,
        name: 'ceshi gong',
        operateDate: DateTime.now(),
        operator: '刘伟'),
    ToolLog(
        id: 13,
        status: 1,
        name: 'ceshi gong',
        operateDate: DateTime.now(),
        operator: '刘伟'),
    ToolLog(
        id: 14,
        status: 1,
        name: 'ceshi gong',
        operateDate: DateTime.now(),
        operator: '刘伟'),
    ToolLog(
        id: 15,
        status: 1,
        name: 'ceshi gong',
        operateDate: DateTime.now(),
        operator: '刘伟'),
    ToolLog(
        id: 16,
        status: 1,
        name: 'ceshi gong',
        operateDate: DateTime.now(),
        operator: '刘伟'),
    ToolLog(
        id: 17,
        status: 1,
        name: 'ceshi gong',
        operateDate: DateTime.now(),
        operator: '刘伟'),
  ];

  @override
  bool operator ==(Object other) {
    if (identical(this, other)) return true;

    return other is ToolLog &&
        other.id == id &&
        other.status == status &&
        other.name == name &&
        other.operateDate == operateDate &&
        other.operator == operator;
  }

  @override
  int get hashCode {
    return id.hashCode ^
        status.hashCode ^
        name.hashCode ^
        operateDate.hashCode ^
        operator.hashCode;
  }
}
